package com.ruoyi.business.service.impl;

import com.ruoyi.auth.service.SysLoginService;
import com.ruoyi.business.service.IBusinessLoginService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("businessLoginService")
public class BusinessLoginServiceImpl implements IBusinessLoginService {
    @Autowired
    private RedisService redisService;

    @Autowired
    private SysLoginService sysLoginService;

    @Autowired
    private TokenService tokenService;

    public R<?> login(String phone, String code){
        /*System.out.println("code:"+code);
        //判断验证码是否正确
        Object cacheObject = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + phone);
        System.out.println("cacheObject"+cacheObject);
        //验证失败
        if (!code.equals(cacheObject.toString())) {
            return R.fail();
        }*/
        //验证成功返回用户信息
        LoginUser userInfo = sysLoginService.businessLogin(phone, code);
        System.out.println(userInfo);
        System.out.println("验证成功返回用户信息");
        // 获取登录token
        return R.ok(tokenService.createToken(userInfo));
    }
}